package main

import (
	"fmt"
	"html/template"
	"io"
	"net/http"
	"strconv"
)

func main() {
	http.HandleFunc("/", index)
	http.HandleFunc("/num", num)
	http.HandleFunc("/enough", enough)
	http.ListenAndServe(":8080", nil)
}

func index(w http.ResponseWriter, r *http.Request) {
	t := template.Must(template.ParseFiles("index.html", "num.html"))
	t.ExecuteTemplate(w, "main", nil)
}

func num(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	num, _ := strconv.Atoi(r.FormValue("num"))
	list := make([]int, num)
	for i := 0; i < num; i++ {
		list[i] = i
	}
	fmt.Println("list:", list)
	t := template.Must(template.ParseFiles("num.html"))
	t.ExecuteTemplate(w, "num", list)
}

func enough(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	num, _ := strconv.Atoi(r.FormValue("num"))
	if num >= 10 {
		io.WriteString(w, "hide")
	}
}
